/*
* Copyright 2023 andy.ian@qq.com All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*     http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#ifndef __LWS_SERVERIMPL_H__
#define __LWS_SERVERIMPL_H__

#include <memory>
#include <string>

#include "libwebsockets.h"

namespace sdk{
namespace message {
namespace proxy {

class MessageProxyImpl {
public:
    explicit MessageProxyImpl();
    explicit MessageProxyImpl(int port, bool bSupportDeflate);
    MessageProxyImpl(int port, bool bSupportDeflate, const char *pathCa, const char *pathCert, const char *pathKey);
    ~MessageProxyImpl();
    int run(int timeout_ms = 0);

private:
    static void NotifyRequestWrite(void *user, int code);
    static int protocol_my_callback(lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);

private:
    bool m_path;
    std::string m_ca;
    std::string m_cert;
    std::string m_key;
    lws_context *m_ctx;
    lws_context_creation_info m_ctxInfo;
    static const lws_protocols protocols[];
    static const lws_extension extensions[];
};

} // namespace proxy
} // namespace message
} // namespace sdk
#endif /* __LWS_SERVERIMPL_H__ */

